﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace cbelo.Helpers { 


    public class NonPaginatedList<T> : List<T> {

        public NonPaginatedList(IQueryable<T> source)
        {
            this.AddRange(source);
        }

    }

    public class HelpersConstants
    {
        static public int MaxPageSize = 8;
    }

    public class PaginatedListPages<T> : List<T>
    {

        public int PageIndex { get; private set; }
        public int PageSize { get; private set; }
        public int TotalCount { get; private set; }
        public int TotalPages { get; private set; }

        public PaginatedListPages(IQueryable<T> source, int pageIndex, int pageSize)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = source.Count();
            TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

            var sourceList = source.ToList();
            var sourceskiped = sourceList.Skip(PageIndex * PageSize);
            var sourcetake = sourceskiped.Take(PageSize);
            this.AddRange(sourcetake);
        }

        public bool HasPreviousPage
        {
            get
            {
                return (PageIndex > 0);
            }
        }

        public bool HasNextPage
        {
            get
            {
                return (PageIndex + 1 < TotalPages);
            }
        }
    }
}
